package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.service.IRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService {
    @Autowired
    private RegionMapper regionMapper;


    @Override
    public Region get(Long id) {
        return null;
    }

    @Override
    public List<Region> listAll() {
        return regionMapper.selectAll();
    }


    @Override
    public List<Region> selectByPrentId(Long parentId) {
        return regionMapper.selectByPrentId(parentId);
    }

    @Override
    public Long saveOrUpdate(Region region) {

        if (region.getId() == null) {
            //没有id表示添加操作
            regionMapper.insert(region);

        } else {
            //有id表示更新操作
            regionMapper.updateByPrimaryKey(region);


        }
        return region.getParent().getId();
    }

    @Override
    public void changeState(Long id, Integer state) {
        regionMapper.changeState(id, state);
    }

    @Override
    public List<Region> listByState(Integer state) {
        return regionMapper.listByState(state);
    }
}
